import time

import requests
from bs4 import BeautifulSoup

url = "https://www.qiushibaike.com/imgrank/page/1/"

headers = {
    'User-Agent': "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.163 Safari/535.1"
}

resp = requests.get(url=url, headers=headers).text

soup = BeautifulSoup(resp, 'lxml')
# 获取thumb这个class下的a标签下的img标签，多个标签形成一个列表
img_list = soup.select('.thumb > a > img')
index = 0
for i in img_list:
    index += 1
    # 遍历列表获取标签内的src属性的值
    url1 = 'https:' + i['src']
    img_info = requests.get(url=url1, headers=headers).content
    with open('./qiushi/' + str(index) + '.jpg', 'wb') as f1:
        f1.write(img_info)
    print('第%s张下载完成!' % str(index))
    time.sleep(0.2)
